package com.zzw.dao;

import com.zzw.model.LoginInfo;
import com.zzw.model.Person;
import com.zzw.model.PersonQuery;
import com.zzw.model.Venue;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface PersonDao {
    @Insert("INSERT INTO a_person(id, name, phone, address, venueId) " +
            "values (#{id}, #{name}, #{phone}, #{address}, #{venueId})")
    int insert(Person person);

    @Select("<script> select  *  from  a_person where 1 = 1 " +
            " <if test = 'id != null'> " +
            " and id = #{id} " +
            "</if>" +
            " <if test = 'name != null'> " +
            " and name like concat ('%',trim(#{name}),'%') " +
            "</if>" +
            " <if test = 'phone != null'> " +
            " and phone = #{phone} " +
            "</if>" +
            " <if test = 'venueId != null'> " +
            " and venueId = #{venueId} " +
            "</if>" +
            "</script>")
    List<Person> select(PersonQuery query);

    @Delete("DELETE FROM a_person WHERE id=#{id}")
    int delete(String id);

    @Update("UPDATE a_person SET " +
            "name=#{name},phone=#{phone}, address=#{address}, venueId=#{venueId} " +
            "WHERE id=#{id}")
    int update(Person person);

    @Update("UPDATE a_person SET venueId=#{venueId} WHERE id=#{id}")
    int updateFaceFlag(Person person);

    @Select("SELECT * FROM a_person WHERE id=#{id} AND phone=#{phone} AND name=#{name} LIMIT 1")
    Person login(LoginInfo loginInfo);
}
